home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1998 August / PC Plus SuperCD 50a Issue 142 (CD142a) (August 1998).iso / handson / supercede / Knowodys / Projects / Primes / 1.0.2 / Primes.java < prev    next >
Encoding:
Java Source  |  1997-09-04  |  825 b   |  42 lines

  1.  
  2. import java.awt.Graphics;
  3.  
  4. public class Primes extends java.applet.Applet {
  5.     int highest = 0;
  6.  
  7.     public Primes () {
  8.     }
  9.  
  10.    public void init()
  11.     {
  12.         Integer i = new Integer(0);
  13.         highest = i.parseInt(getParameter("highest"));
  14.     }
  15.  
  16.     public void paint(Graphics g)
  17.     {
  18.         int row = 1, col=1;
  19.  
  20.         boolean isPrime;
  21.  
  22.         for (int theNum = 1;theNum<=highest;theNum++) {
  23.             isPrime = true;
  24.             innloop: for (int i = 2; i <= theNum/2; i++){
  25.                 if ((theNum % i) == 0) {
  26.                     isPrime = false;
  27.                     break innloop;
  28.                 }
  29.             }
  30.             if (isPrime) {
  31.                 g.drawString(" "+theNum,30*col++,20*row);
  32.                 if (col == 10){
  33.                     col = 1;
  34.                     row++;
  35.                 }
  36.             }
  37.         }
  38.     }
  39. }
  40.  
  41.  
  42.